﻿using BrightIdeasSoftware;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FormTest
{
    public class UcVirtualListView:VirtualObjectListView
    {
        private ImageList _iconImageList;

        public class Product
        {
            public int Id { get; set; }
            public string Name { get; set; }
            public decimal Price { get; set; }
            public int Stock { get; set; }
            public bool IsActive { get; set; }
        }

        public UcVirtualListView() 
        {
            Dock = DockStyle.Fill;
            View = View.Details;
            FullRowSelect = true;
            GridLines = true;   
            VirtualListSize = 0;    
            UseAlternatingBackColors = true;
            RowHeight = 30;
            SmallImageList= _iconImageList;
            HeaderWordWrap = true;//用于控制列标题（ColumnHeader）是否自动换行显示。当列标题文本较长时，启用此属性可以避免标题被截断，提升可读性。                             
            //HeaderFont = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point);// 可选：设置标题字体（影响换行效果）

            Columns.AddRange(new OLVColumn[]
            {
                new OLVColumn("产品编号", "Id") { Width = 80 },
                new OLVColumn("产品名称", "Name") { Width = 150 },
                new OLVColumn("产品单价（元）", "Price")
                {
                    Width = 120,
                    AspectToStringConverter = val => $"{Convert.ToDecimal(val):C2}",
                    TextAlign = HorizontalAlignment.Right
                },
                new OLVColumn("库存数量（件）", "Stock") { Width = 120 },
                new OLVColumn("是否处于在售状态", "IsActive")
                {
                    Width = 150,
                    AspectToStringConverter = val => (bool)val ? "是" : "否"
                }
            });
        }
    }
}
